#include "CharacterBall.h"
#define N 20

CharacterBall::CharacterBall()
    :Character(3.0,AABB(vector3<float>(0,0,0),vector3<float>(0.9,0.9,0.9)))
    ,gamestate(GameStates::getInstance())
    ,rend(RenderManager::getInstance())
{
    index=0;
    //translate(vector3<float>(WORLD_SIZE/2,100,WORLD_SIZE-100));
}

Character* CharacterBall::getInstance(){
    static Character* inst=0;
    if(!inst)return inst=new CharacterBall();
    else return inst;
}

void CharacterBall::render(){
    hpDelay--;
    glPushMatrix();
    glTranslatef(s.position.x,s.position.y, s.position.z);

    if(!index){
        index=glGenLists(1);

        glNewList(index,GL_COMPILE_AND_EXECUTE);
        glColor3f(1,0,0);
        Drawing::drawCube(vector3<float>(0.5,0.5,0.5),0.5);
        glEndList();

    }else glCallList(index);

    glPopMatrix();
}

void CharacterBall::goForward(){
    vector3<float> step = (vector3<float>(rend->Camera.getLookAtVector().x,0,rend->Camera.getLookAtVector().z)).unit();
    s.velocity.x=step.x*gamestate->getStepSize();
    s.velocity.z=step.z*gamestate->getStepSize();
}

void CharacterBall::goBackward(){
    vector3<float> step = (vector3<float>(-rend->Camera.getLookAtVector().x,0,-rend->Camera.getLookAtVector().z)).unit();
    s.velocity.x=step.x*gamestate->getStepSize();
    s.velocity.z=step.z*gamestate->getStepSize();
}

void CharacterBall::goLeft(){
    vector3<float> step = (vector3<float>(-rend->Camera.getStrideVector().x,0,-rend->Camera.getStrideVector().z)).unit();
    s.velocity.x=step.x*gamestate->getStepSize();
    s.velocity.z=step.z*gamestate->getStepSize();
}

void CharacterBall::goRight(){
    vector3<float> step = (vector3<float>(rend->Camera.getStrideVector().x,0,rend->Camera.getStrideVector().z)).unit();
    s.velocity.x=step.x*gamestate->getStepSize();
    s.velocity.z=step.z*gamestate->getStepSize();
}

void CharacterBall::Jump(){
    s.velocity.y = gamestate->getJumpHeight();
}
